package com.food.foodapi.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisUtil {

    @Autowired
    private StringRedisTemplate redisTemplate;

    private static final String TOKEN_PREFIX = "user:token:";

    // 存储 Token 到 Redis
    public void saveToken(String username, String token) {
        redisTemplate.opsForValue().set(TOKEN_PREFIX + username, token);
    }

    // 从 Redis 获取 Token
    public String getToken(String username) {
        return redisTemplate.opsForValue().get(TOKEN_PREFIX + username);
    }

    // 删除 Redis 中的 Token
    public void deleteToken(String username) {
        redisTemplate.delete(TOKEN_PREFIX + username);
    }
}

